Skip to content

⚡ Bolt: Optimize chained array operations in core utilities#46

Merged
Howchie merged 2 commits intomainfrom
bolt-optimize-chained-arrays-2913135739689122817
Apr 10, 2026
Merged

⚡ Bolt: Optimize chained array operations in core utilities#46
Howchie merged 2 commits intomainfrom
bolt-optimize-chained-arrays-2913135739689122817

Conversation

@Howchie
Copy link
Copy Markdown
Owner

@Howchie Howchie commented Mar 19, 2026

💡 What: Replaced several instances of chained array operations (.map().filter().map() and .map().filter().reduce()) with single for loops across multiple utility and engine files in the @experiments/core package.
🎯 Why: Chained array methods allocate a new intermediate array at every step. In functions like toNumberArray, asStringArray, and computeScores, which may be called frequently or operate on moderately sized arrays, this creates unnecessary memory allocations and garbage collection overhead.
📊 Impact: Eliminates N intermediate array allocations for an array of size N in each operation, improving memory efficiency and reducing execution time in these specific code paths.
🔬 Measurement: Run the test suite (npm run test --workspaces --if-present). No regressions should occur. Micro-benchmarks of toNumberArray or similar utility functions would show improved performance and reduced memory allocations compared to the chained version.


PR created automatically by Jules for task 2913135739689122817 started by @Howchie

Replace multiple chained array operations (`.map().filter().map()`, `.map().filter().reduce()`) with single `for` loops in:
- `packages/core/src/engines/stimulusInjector.ts`
- `packages/core/src/engines/prospectiveMemory.ts`
- `packages/core/src/utils/coerce.ts`
- `packages/core/src/web/surveys.ts`

This eliminates unnecessary intermediate array allocations, reducing memory usage and garbage collection overhead, particularly in high-frequency paths.
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@Howchie Howchie merged commit 77dc175 into main Apr 10, 2026
@Howchie Howchie deleted the bolt-optimize-chained-arrays-2913135739689122817 branch April 10, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant